<?php
/**
 * Created by PhpStorm.
 * User: ytlmi
 * Date: 2018/3/12
 * Time: 10:37
 */

namespace org\util\wordTool\example;

use org\util\forensicTool\ForensicCalculate;

class Report3l extends ReportQz
{
    /**
     * @throws \Exception
     */
    protected function addDetectionTable()
    {
        $roleGroup = $this->makeRoleGroup();

        //设置单元格宽度
        $positionMap = ['first' => self::FIRST_ROW_STYLE, 'mid' => self::MID_ROW_STYLE, 'last' => self::LAST_ROW_STYLE];
        $width = [1500, 1500, 1500, 2000, 1500];

        //每个亲代与每个子代生成对比表格
        $tableIndex = 0;
        foreach ($roleGroup[1] as $child) {
            $tableIndex++;
            $calResult = ForensicCalculate::instance()
                ->setCaseType($this->caseData['case_type'])
                ->setGenotypeF($this->caseData['samples']['F']['genotype'])
                ->setGenotypeM($this->caseData['samples']['M']['genotype'])
                ->setGenotypeC($this->caseData['samples'][$child]['genotype'])
                ->setFrequency($this->frequency)
                ->setMutation($this->mutation)
                ->calculate();//计算
            $childSampleName = $this->caseData['samples'][$child]['sample_name'];//样品名
            $fatherSampleName = $this->caseData['samples']['F']['sample_name'];//样品名
            $motherSampleName = $this->caseData['samples']['M']['sample_name'];//样品名
            $arrMarker = array_keys($calResult);//全部基因座
            $tableDes = '表' . $tableIndex . '：' . $childSampleName . '和' . $fatherSampleName . '、' . $motherSampleName . '号检材STR基因座的基因分型结果';//表头
            $tableHead = ['基因座', $motherSampleName, $childSampleName, $fatherSampleName, '亲权指数'];//第一行
            $this->body->addPr($tableDes, self::TABLE_DES_FONT, self::TEXT_TAB);
            $table = $this->body->addTable(self::TABLE_STYLE);
            $table->addSimpleRow($tableHead, $width, self::TABLE_FONT, $positionMap['first']);
            foreach ($calResult as $marker => $result) {
                $pi = isset($result[0]) ? sprintf("%.2f", $result[0]) : '-';//无计算结果时用“-”代替
                $alleleC = $this->caseData['samples'][$child]['genotype'][$marker];//孩子在当前基因座的基因型
                $alleleF = $this->caseData['samples']['F']['genotype'][$marker];//亲代基因型
                $alleleM = $this->caseData['samples']['M']['genotype'][$marker];//亲代基因型
                $content = [$marker, $alleleM[0] . ',' . $alleleM[1], $alleleC[0].','.$alleleC[1], $alleleF[0] . ',' . $alleleF[1], $pi];
                $position = $marker == end($arrMarker) ? 'last' : 'mid';
                $table->addSimpleRow($content, $width, self::TABLE_FONT, $positionMap[$position]);
            }
        }

    }
}